#!/bin/bash

# 自动测试 Shielded.Gossip 3节点集群
# 启动3个节点，分别监听9901, 9902, 9903，输出到不同日志
# 运行10秒后自动关闭所有节点

set -e

PEERS="A@127.0.0.1:9901,B@127.0.0.1:9902,C@127.0.0.1:9903"

# 启动节点A
nohup dotnet run --project ConsoleApp1 -- --id=A --peers=$PEERS > nodeA.log 2>&1 &
PID_A=$!
# 启动节点B
nohup dotnet run --project ConsoleApp1 -- --id=B --peers=$PEERS > nodeB.log 2>&1 &
PID_B=$!
# 启动节点C
nohup dotnet run --project ConsoleApp1 -- --id=C --peers=$PEERS > nodeC.log 2>&1 &
PID_C=$!

echo "Started nodes: $PID_A $PID_B $PID_C"
echo "Logs: nodeA.log nodeB.log nodeC.log"

echo "Testing for 10 seconds..."
sleep 10

echo "Stopping all nodes..."
kill $PID_A $PID_B $PID_C
wait $PID_A $PID_B $PID_C 2>/dev/null || true

echo "Test complete. Check nodeA.log, nodeB.log, nodeC.log for output." 